﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using FTchina;
using System.Collections;
using FTchina.Library;
namespace FTchina.OA
{
    /// <summary>
    ///ModifyMobile 的摘要说明
    /// </summary>
    public class shoujihao
    {


        /// <summary>
        /// 批量修改手机号码,门户获取密码用
        /// </summary>
        /// <param name="al">格式weibh:15605468613</param>
        public static void ModifyMobile(ArrayList al, out string Error)
        {
            Error = "";

            //修改成功短信提醒
            string mesage = "此手机号已经与账户{0}关联，可以通过门户首页点击“遗忘密码”获取账户密码。";
            string mfrom = "OA系统";
            string merror = string.Empty;//短信错误日志


            string uname = "weibh";//具有渠道管理权限的用户名密码
            string upsw = "wbh123!!";

            string loginurl = "http://www.sd.unicom.local/pkmslogin.form";
            string poststr = "userPortal=&username=" + uname + "&password=" + upsw + "&login-form-type=pwd";
            //登录
            basic.PostHttphtml(loginurl, Encoding.UTF8, poststr);
            // LogNet.LogBLL.debug("登录" + PostHttphtml(loginurl, Encoding.UTF8, poststr));


            //系统管理
            string quanguourl = "http://www.sd.unicom.local/was/wps/myportal/dy/!ut/p/c1/04_SB8K8xLLM9MSSzPy8xBz9CP0os3iPoDBvczdTEwP3AA8nA09v7xDzEHd3A_dgY6B8JJK8gYWFC1DexDUkINDPwNnPiIDucJB9-PWD5A1wAEcDNP3oNhjq-3nk56bqF-RGGGQGpCsCAGp1DyE!/dl2/d1/L2dJQSEvUUt3QS9ZQnB3LzZfSFJWSzdGNTQwR1BIQjBJS0tUN1RHRzBHUzE!/";
            basic.GetHttphtml(quanguourl, Encoding.UTF8);
            // LogNet.LogBLL.debug("系统管理" + GetHttphtml(quanguourl, Encoding.UTF8));





            string url1 = "http://www.sd.unicom.local/pkmscdsso?http://www.unicom.local/yggl/HumanManager/user/index.do";

            string url3 = "http://www.unicom.local/yggl/HumanManager/user/index.do?PD-REFERER=www.sd.unicom.local&PD-ID=tJ+q49yaz73bj+6nWk3IOC3Gb+ELimaWn2LYtiaF/xtk6XrzOqrKUh1aRcEfSaIAPJzCJZcoCYhJTM/oFlpv0c7FWWakWirhuiFAcrQHU1VYfZyjdQWMWgP2mlp07CsPzjCtgJokCu0=";
            string url2 = "http://www.sd.unicom.local/st/PageTransfer/loginst.html ";
            //LogNet.LogBLL.debug("跳转1" + GetHttphtml(url1, Encoding.UTF8));
            //LogNet.LogBLL.debug("跳转2" + GetHttphtml(url2, Encoding.UTF8));
            //LogNet.LogBLL.debug("跳转3" + GetHttphtml(url3, Encoding.UTF8));
            basic.GetHttphtml(url1, Encoding.UTF8);
            basic.GetHttphtml(url2, Encoding.UTF8);
            basic.GetHttphtml(url3, Encoding.UTF8);





            //测试系统是否存在此用户
            string Chkurl = "http://www.unicom.local/yggl/HumanManager/user/edituser.do?uid={0}";

            // LogNet.LogBLL.info(ChkResult.ToString());


            //修改手机号
            string mobstr = "http://www.unicom.local/HumanManager/user/editusersubmit.do";
            string mobpost = "custarttime=1999-12-16&cuendtime=2099-12-18&mobile={1}&hasroles=mdm@cuuserrole_default@&uid={0}";



            bool ChkResult = true;

            foreach (string str in al)
            {
                string uoa = str.Split(':')[0];
                string uid = basic.Base64En(uoa);
                string mobile = str.Split(':')[1];

                ChkResult = basic.GetHttphtml(string.Format(Chkurl, uid), Encoding.UTF8).Contains("@chinaunicom.cn");//检查是否有账户
                if (ChkResult)
                {//有账户

                    if (basic.PostHttphtml(mobstr, Encoding.UTF8, string.Format(mobpost, uid, mobile)).Trim() == "")
                    {
                        LogHelper.Info(uoa + mobile + "OK,短信" + FTchina.OA.UnicomSMS.SendSingle(mobile, mfrom, string.Format(mesage, uoa), out merror));
                        Error += uoa + ":" + mobile + "&nbsp;&nbsp;成功&nbsp;&nbsp;" + DateTime.Now.ToString() + "<br>";
                        
                        #region 日志
                        FTchina.Models.Moblie_Log mMoblie_Log = new FTchina.Models.Moblie_Log();
                        mMoblie_Log.Id = 0;

                        mMoblie_Log.Uaccount = uoa;
                        mMoblie_Log.Mobile = mobile;
                        mMoblie_Log.Dt = DateTime.Now;
                        mMoblie_Log.Ip = RequestHelper.GetUserIp();
                        mMoblie_Log.UName = MasterHelper.UName;
                        FTchina.BLL.Moblie_LogManager.AddOrUpdateMoblie_Log(mMoblie_Log);

                        #endregion
                    }
                    else
                    {
                        Error += uoa + "手机号修改失败" + DateTime.Now.ToString() + "<br>";
                        LogHelper.Info(uoa + mobile + "False");

                    }
                }
                else
                {
                    Error += uoa + "无此账户  " + DateTime.Now.ToString() + "<br>";
                }
            }






        }








    }
}